<?php
! defined ( 'IN_ROOT' ) && exit ( 'Access Denied' );
class sysmapmodel {
	
	var $db;
	var $base;
	
	function sysmapmodel(&$base) {
		$this->base = $base;
		$this->db = $base->db;
	}
	//分站分类管理========================================================================================
	//$tid 1国内游 2周边游 3出境游
	function get_sitelist($id = '', $tid = 1) {
		$str = '';
		$maparray = array ();
		if (is_numeric ( $id )) {
			$mdb = $this->db->query ( "SELECT cid FROM `" . DB_TABLEPRE . "mapsitecate` WHERE sid='$id' and tid='$tid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$maparray [] = $m ['cid'];
			}
		}
		
		$query = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "catesys` where mid=0" );
		while ( $cate = $this->db->fetch_array ( $query ) ) {
			$str .= '<br /><b>' . $cate [name] . '</b><br />';
			$rs = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "cate` where tid='$cate[id]' order by views asc" );
			while ( $t = $this->db->fetch_array ( $rs ) ) {
				if (in_array ( $t ['id'], $maparray )) {
					$check = ' checked';
					$name = '<a href="index.php?admin_site/areas/' . $id . '/' . $tid . '/' . $t ['id'] . '">' . $t [name] . '</a>';
				} else {
					$check = '';
					$name = $t [name];
				}
				$str .= '&nbsp;&nbsp;<input type="checkbox" value="' . $t [id] . '" name="cates[]"' . $check . '>' . $name . '';
			}
		}
		return $str;
	}
	function get_sitelistindex($id) {
		$str = '';
		$maparray = $a = array ();
		//$sys = array(1=>'国内游',2=>'周边游',3=>'出境游');
		$sys = array();
		$sql="SELECT id,name FROM my_cateconfig";
	        $query=$this->db->query($sql);
	        while($item=$this->db->fetch_array($query)) {
	                $sys[$item['id']]=$item['name'];
	        }
		foreach($sys as $i => $n ) {
			$mdb = $this->db->query ( "SELECT m.cid,c.name FROM `" . DB_TABLEPRE . "mapsitecate` as m left join `" . DB_TABLEPRE . "cate` as c on m.cid=c.id WHERE m.sid='$id' and m.tid='$i'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$maparray[$i]['name'] = $n;
				$maparray[$i][$m['cid']]['top'] = $m['name'];
				//
				//$db = $this->db->query ( "SELECT aid FROM `" . DB_TABLEPRE . "mapsitearea` WHERE sid='$id' and cid='$m[cid]' and tid='$i'" );
				
				$db = $this->db->query ( "SELECT m.aid,s.name,s.ename FROM `" . DB_TABLEPRE . "mapsitearea` as m left join `" . DB_TABLEPRE . "area` as s on m.aid=s.id WHERE m.sid='$id' and m.cid='$m[cid]' and m.tid='$i'" );
				while ( $t = $this->db->fetch_array ( $db ) ) {
					if(!empty($t['ename'])){
						$t['name'] = $t['ename'];
					}
					$maparray[$i][$m['cid']]['foot'][] = $t;
				}
				
				
			}
		}
		/*
		foreach ($maparray as $k => $v ) {
			//$db = $this->db->query ( "SELECT m.aid,s.name as sname,s.ename as sename FROM `" . DB_TABLEPRE . "mapsitearea` as m left join `" . DB_TABLEPRE . "area` as s on m.aid=s.id WHERE m.sid='$id' and m.cid='$m[cid]' and m.tid='$i'" );
			foreach ($v as $kk => $vv ){
				$db = $this->db->query ( "SELECT m.aid,s.name,s.ename FROM `" . DB_TABLEPRE . "mapsitearea` as m left join `" . DB_TABLEPRE . "area` as s on m.aid=s.id WHERE m.sid='$id' and m.cid='$kk' and m.tid='$k'" );
				while ( $t = $this->db->fetch_array ( $db ) ) {
					if(!empty($t['ename'])){
						$t['name'] = $t['ename'];
					}
					$a[$k][$kk][] = $t;
				}
			}
			
		}
		*/
		return $maparray;
	}
    function get_linelist($siteid,$sysid,$cateid,$areaid) {
            $sublist = array ();
            $sql = "select 
                m.lid,l.title,l.traffic
                from " . DB_TABLEPRE . "mapline as m 
                left join " . DB_TABLEPRE . "line as l
                on l.id=m.lid 
                where m.sid='$siteid' and m.cid='$cateid' and m.aid='$areaid' and m.tid='$sysid' 
                order by m.id desc";
            $query = $this->db->query ($sql);
            while ( $category = $this->db->fetch_array ( $query ) ) {
            	$jd = $this->db->query("select m.vid,v.name,v.sname from ".DB_TABLEPRE."maplineview as m left join ".DB_TABLEPRE."views as v on m.vid=v.id  where m.lid='$category[lid]'");
				while ( $jr = $this->db->fetch_array ( $jd ) ) {
					$category['view'][] = $jr;
				}
				$sublist [] = $category;
				
            }
            //var_dump($sublist);
            return $sublist;
        }
	function insitecate($sid, $typeid, $cates) {
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapsitecate`(`sid` ,`cid`,`tid`) VALUES ";
		foreach ( $cates as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$sid','$v','$typeid'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function delsitecate($sid, $tid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapsitecate` WHERE `sid`='$sid' and tid='$tid'" );
	}
	//分站地区管理========================================================================================
	

	function delcate($sid, $type, $cid, $cids) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapsitearea` WHERE `sid`='$sid' and `aid` IN ($cids) and cid='$cid' and tid='$type'" );
	}
	function addcate($sid, $type, $cid, $cids) {
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapsitearea`(`sid` ,`cid` , `aid`,`tid`) VALUES ";
		foreach ( $cids as $v ) {
			if (empty ( $v ))
				continue;
			$v = ( int ) $v;
			$sql .= "('$sid','$cid', '$v','$type'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		//var_dump($sql);exit();
		return $this->db->query ( $sql );
	}
	function addareatag($name, $aid) {
		$this->db->query ( 'UPDATE `' . DB_TABLEPRE . "area` SET ename='$name' WHERE `id`='$aid'" );
	}
	function list_by_cid_pid_area($aid, $pid, $cid, $sid, $type = 0) {
		$sublist = array ();
		$query = $this->db->query ( "select id,name,grade,ename from " . DB_TABLEPRE . "area where pid=$aid order by displayorder asc,id asc" );
		$subcount = $this->db->affected_rows ();
		if ($subcount <= 0) {
			$query = $this->db->query ( "select id,name,grade,ename from " . DB_TABLEPRE . "area where pid=$pid order by displayorder asc,id asc" );
		}
		while ( $category = $this->db->fetch_array ( $query ) ) {
			$category ['mid'] = ( int ) $this->db->result_first ( "SELECT id FROM `" . DB_TABLEPRE . "mapsitearea` where sid='$sid' and aid='$category[id]' and cid='$cid' and tid='$type'" );
			$sublist [] = $category;
		}
		return $sublist;
	}
	function get_navigation_area($cid = 0, $contain = false) {
		$navlist = array ();
		do {
			$category = $this->base->area [$cid];
			if ($category) {
				$cid = $category ['pid'];
				$navlist [] = $category;
			}
		} while ( $category && $cid );
		$navlist = array_reverse ( $navlist );
		! $contain && array_pop ( $navlist ); //是否需要本分类
		return $navlist;
	}
	//分站同业分类管理========================================================================================
	function get_site($id = '') {
		$str = '';
		$maparray = array ();
		if (is_numeric ( $id )) {
			$mdb = $this->db->query ( "SELECT cid FROM `" . DB_TABLEPRE . "mapsiteout` WHERE sid='$id'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$maparray [] = $m ['cid'];
			}
		}
		
		$query = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "cateconfig`" );
		while ( $cate = $this->db->fetch_array ( $query ) ) {
			$str .= '<br /><b>' . $cate [name] . '</b><br />';
			$rs = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "cateout` where tid='$cate[id]' order by views asc" );
			while ( $t = $this->db->fetch_array ( $rs ) ) {
				if (in_array ( $t ['id'], $maparray )) {
					$check = ' checked';
				} else {
					$check = '';
				}
				$str .= '&nbsp;&nbsp;<input type="checkbox" value="' . $t [id] . '" name="outcate[]"' . $check . '>' . $t [name] . '';
			}
		}
		return $str;
	}
	function insiteout($sid, $cids) {
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapsiteout`(`sid` ,`cid`) VALUES ";
		foreach ( $cids as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$sid','$v'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function delsiteout($sid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapsiteout` WHERE `sid`='$sid'" );
	}
	
	//景点分类管理========================================================================================
	function get_viewslist($id = '') {
		$str = '';
		$maparray = array ();
		if (is_numeric ( $id )) {
			$mdb = $this->db->query ( "SELECT cid FROM `" . DB_TABLEPRE . "mapviewcate` WHERE vid='$id'" );
			//var_dump("SELECT cid FROM `".DB_TABLEPRE."mapviewcate` WHERE vid='$id'");exit();
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$maparray [] = $m ['cid'];
			}
		}
		
		$query = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "catesys`" );
		while ( $cate = $this->db->fetch_array ( $query ) ) {
			$str .= '<br /><b>' . $cate [name] . '</b><br />';
			$rs = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "cate` where tid='$cate[id]' order by views asc" );
			while ( $t = $this->db->fetch_array ( $rs ) ) {
				if (in_array ( $t ['id'], $maparray )) {
					$check = ' checked';
				} else {
					$check = '';
				}
				$str .= '&nbsp;&nbsp;<input type="checkbox" value="' . $t [id] . '" name="cates[]"' . $check . '>' . $t [name] . '';
			}
		}
		return $str;
	}
	function inviewscate($vid, $cates) {
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapviewcate`(`vid` ,`cid`) VALUES ";
		foreach ( $cates as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$vid','$v'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function delviewscate($vid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapviewcate` WHERE `vid`='$vid'" );
	}
	//用户同业分类管理========================================================================================
	function get_user($id = '') {
		$str = '';
		$maparray = array ();
		if (is_numeric ( $id )) {
			$mdb = $this->db->query ( "SELECT cid FROM `" . DB_TABLEPRE . "mapuserout` WHERE uid='$id'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$maparray [] = $m ['cid'];
			}
		}
		
		$query = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "cateconfig`" );
		while ( $cate = $this->db->fetch_array ( $query ) ) {
			$str .= '<br /><b>' . $cate [name] . '</b><br />';
			$rs = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "cateout` where tid='$cate[id]' order by views asc" );
			while ( $t = $this->db->fetch_array ( $rs ) ) {
				if (in_array ( $t ['id'], $maparray )) {
					$check = ' checked';
				} else {
					$check = '';
				}
				$str .= '&nbsp;&nbsp;<input type="checkbox" value="' . $t [id] . '" name="outcate[]"' . $check . '>' . $t [name] . '';
			}
		}
		return $str;
	}
	function inuserout($sid, $cids) {
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapuserout`(`uid` ,`cid`) VALUES ";
		foreach ( $cids as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$sid','$v'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function deluserout($sid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapuserout` WHERE `uid`='$sid'" );
	}
	//用户可发布分站管理========================================================================================
	function get_user_select($uid) {
		$str = '<select name="sid">';
		$sid = $this->db->result_first ( "SELECT sid FROM `" . DB_TABLEPRE . "mapusersite` where uid='$uid' limit 0,1" );
		$query = $this->db->query ( "SELECT id,name FROM `" . DB_TABLEPRE . "site` ORDER BY `id` ASC" );
		while ( $v = $this->db->fetch_array ( $query ) ) {
			if ($sid == $v ['id'])
				$select = 'selected';
			else
				$select = '';
			$str .= '<option value="' . $v ['id'] . '" ' . $select . '>' . $v ['name'] . '</option>';
		}
		return $str . '</select>';
	}
	function get_pifa_site($uid) {
		$uarray = array ();
		$mdb = $this->db->query ( "SELECT m.sid,s.name FROM `" . DB_TABLEPRE . "mapusersite` as m left join `" . DB_TABLEPRE . "site` as s on s.id=m.sid WHERE m.uid='$uid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$uarray[] = $m;
			}
		return $uarray;
	}
	function get_pifa_area($uid) {
		$uarray = array ();
		$mdb = $this->db->query ( "SELECT m.aid,s.name FROM `" . DB_TABLEPRE . "mapuserarea` as m left join `" . DB_TABLEPRE . "area` as s on s.id=m.aid WHERE m.uid='$uid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$uarray[] = $m;
			}
		return $uarray;
	}
	function get_user_checkbox($uid) {
		$uarray = array ();
		if (is_numeric ( $uid )) {
			$mdb = $this->db->query ( "SELECT sid FROM `" . DB_TABLEPRE . "mapusersite` WHERE uid='$uid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$uarray [] = $m ['sid'];
			}
		}
		$query = $this->db->query ( "SELECT id,name FROM `" . DB_TABLEPRE . "site` ORDER BY `pinyin` ASC" );
		while ( $v = $this->db->fetch_array ( $query ) ) {
			if (in_array ( $v ['id'], $uarray ))
				$select = 'checked';
			else
				$select = '';
			$str .= '<input type="checkbox" name="sids[]" value="' . $v ['id'] . '" ' . $select . '>' . $v ['name'] . '&nbsp;&nbsp;';
		}
		return $str;
	}
	function inusersite($uid, $cids) {
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapusersite`(`uid` ,`sid`) VALUES ";
		foreach ( $cids as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$uid','$v'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function delusersite($uid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapusersite` WHERE `uid`='$uid'" );
	}
	/*
	function get_user_area($uid) {
		$uarray = $sarray = array ();
		$str = $ustr = '';
		if (is_numeric ( $uid )) {
			//获得用户已经分配的地区
			$mdb = $this->db->query ( "SELECT aid FROM `" . DB_TABLEPRE . "mapuserarea` WHERE uid='$uid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$uarray [] = $m ['aid'];
			}
			//var_dump($uarray);
			//获取用户能发布的地区
			$sdb = $this->db->query ( "SELECT sid FROM `" . DB_TABLEPRE . "mapusersite` WHERE uid='$uid'" );
			while ( $t = $this->db->fetch_array ( $sdb ) ) {
				$sarray [] = $t ['sid'];
			}
			//var_dump($sarray);
			$ustr = implode ( ",", $sarray );
			$query = $this->db->query ( "SELECT distinct m.aid,a.name FROM `" . DB_TABLEPRE . "mapsitearea` as m left join `" . DB_TABLEPRE . "area` as a on a.id=m.aid where sid in($ustr) order by a.pinyin asc" );
			while ( $v = $this->db->fetch_array ( $query ) ) {
				if (in_array ( $v ['aid'], $uarray ))
					$select = 'checked';
				else
					$select = '';
				$str .= '<input type="checkbox" name="cates[' . $v ['aid'] . ']" value="' . $v ['aid'] . '" ' . $select . '>' . $v ['name'] . '&nbsp;&nbsp;';
			}
		}
		
		return $str;
	}
	*/
	function inuserarea($uid, $cids) {
		//var_dump($cids);exit();
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapuserarea`(`uid` ,`aid`,`k1`,`k2`,`k3`) VALUES ";
		foreach ( $cids as $k1 => $v1 ) {
			if (empty ( $v1 ))continue;
			foreach ( $v1 as $k2 => $v2 ) {
				if (empty ( $v2 ))continue;
				foreach ( $v2 as $k3 => $v3 ) {
					if (empty ( $v3 ))continue;
					foreach ( $v3 as $k4 => $v4 ) {
						if (empty ( $v4 ))continue;
						$sql .= "('$uid','$k4','$k1','$k2','$k3'),";
					}
				}
			}
			
		}
		$sql = substr ( $sql, 0, - 1 );
		//var_dump($sql);exit();
		return $this->db->query ( $sql );
	}
	function get_user_area($uid) {
		$uarray = $sarray = array ();
		$str = $ustr = '';
		$cateconfig = $this->base->cateconfig;
		$catesys = $this->base->catesys;
		$cateuse = $this->base->cateuse;
		//var_dump($cateconfig);
		if (is_numeric ( $uid )) {
			//获得用户已经分配的地区
			$mdb = $this->db->query ( "SELECT aid,k1,k2,k3 FROM `" . DB_TABLEPRE . "mapuserarea` WHERE uid='$uid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				$uarray [] = $m;
			}
			//var_dump($uarray);
			//获取用户能发布的地区
			$sdb = $this->db->query ( "SELECT m.sid,s.name FROM `" . DB_TABLEPRE . "mapusersite` as m left join my_site as s on m.sid=s.id WHERE m.uid='$uid'" );
			$sarr = $sd = array();
			while ( $t = $this->db->fetch_array ( $sdb ) ) {
				$sarr[$t['sid']] = $t['name'];
			}
			$sd = $this->base->getsites_cache($sarr);
			foreach ($sd as $k => $v1) {
				$str .= '<br /><br /><br /><br />================================<b>'.$sarr[$k].'站</b>==========================================<br /><br />';
				foreach ($v1 as $k2 => $v2) {
					$str .= '<br /><br />&nbsp;&nbsp;---------><b>'.$v2['name'].'</b><--------------------<br /><br />';
					foreach ($v2 as $k3 => $v3){
						if(strlen($v3['top'])>2){
							$str .= '<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;---->'.$v3['top'].'<br /><br />';
							if(is_array($v3['foot'])){
								foreach ($v3['foot'] as $v4){
									$select = '';
									foreach ($uarray as $k5 => $v5 ){
										if($v5['aid']==$v4['aid'] && $v5['k1']==$k &&  $v5['k2']==$k2 &&  $v5['k3']==$k3){
											$select = 'checked';
										}
									}
									$str .= '<input type="checkbox" value="'.$v4['aid'].'" name="cates['.$k.']['.$k2.']['.$k3.']['.$v4['aid'].']" ' . $select . '>'.$v4['name'].'&nbsp;&nbsp;';
								}
							}
						}
						
					}
				}
			}
			//var_dump($sdd);
			/*
			while ( $t = $this->db->fetch_array ( $sdb ) ) {
				$str .= '<br /><br />-------------<b>'.$t ['name'].'站</b>---------------------<br /><br />';
				$sitedb = $this->base->getsite_cache($sid);
				var_dump($sitedb);
				foreach ($sitedb as $v) {
					$str .= '<br />&nbsp;&nbsp;-->'.$v['name'].'<--<br /><br />';
				}
				
				foreach ($cateconfig as $cg) {
					$str .= '<br />&nbsp;&nbsp;-->'.$cg['name'].'<--<br /><br />';
					foreach ($catesys as $sg) {
						if($sg[mid] == 0){
							$str .= '&nbsp;&nbsp;&nbsp;&nbsp;---->'.$sg['name'].$sg['id'].'<br />';
							$cdb = $this->db->query ( "SELECT cid FROM my_mapsitecate` WHERE sid='$t[sid]' and tid='$sg[id]'" );
							while ( $m = $this->db->fetch_array ( $cdb ) ) {
								//$str .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->'.$m ['cid'].'<br />';
							}
						}
						
					}
					
					$mdb = $this->db->query ( "SELECT cid FROM `" . DB_TABLEPRE . "mapsitecate` WHERE sid='$id' and tid='$tid'" );
					while ( $m = $this->db->fetch_array ( $mdb ) ) {
						$maparray [] = $m ['cid'];
					}
					$cdb = $this->db->query ( "SELECT m.cid,c.name FROM `" . DB_TABLEPRE . "mapsitecate` as m left join my_cate as c on m.cid=c.id WHERE m.sid='$t[sid]' and m.tid='$sg[id]'" );
							while ( $c = $this->db->fetch_array ( $mdb ) ) {
								$str .= '&nbsp;&nbsp;-->'.$c['name'].'<br />';
							}
				
				}
				
			}
			*/
			
		}
		
		return $str;
	}
	
	function get_user_area_pifa($uid,$lid=0) {
		$uarray = $sarray = array ();
		$str = $ustr = '';
		$cateconfig = $this->base->cateconfig;
		$catesys = $this->base->catesys;
		$cateuse = $this->base->cateuse;
		//var_dump($cateconfig);
		$ak1 = $ak2 = $ak3 = $ak = array();
		if (is_numeric ( $uid )) {
			//获得用户已经分配的地区
			$mdb = $this->db->query ( "SELECT aid,k1,k2,k3 FROM `" . DB_TABLEPRE . "mapuserarea` WHERE uid='$uid'" );
			while ( $m = $this->db->fetch_array ( $mdb ) ) {
				//$uarray [] = $m;
				$ak[$m['aid']] = $m['aid'];
				$ak1[$m['k1']] = $m['k1'];
				$ak2[$m['k2']] = $m['k2'];
				$ak3[$m['k3']] = $m['k3'];
			}
			//var_dump($uarray);
			//获取编辑的数据
			if(is_numeric($lid) && $lid>0){
				$ldb = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "mapline` WHERE lid='$lid'" );
				while ( $t = $this->db->fetch_array ( $ldb ) ) {
					$uarray [] = $t;
				}
			}
			//获取用户能发布的地区
			$sdb = $this->db->query ( "SELECT m.sid,s.name FROM `" . DB_TABLEPRE . "mapusersite` as m left join my_site as s on m.sid=s.id WHERE m.uid='$uid'" );
			$sarr = $sd = array();
			while ( $t = $this->db->fetch_array ( $sdb ) ) {
				$sarr[$t['sid']] = $t['name'];
			}
			
			
			$sd = $this->base->getsites_cache($sarr);
			foreach ($sd as $k => $v1) {
				if(!in_array($k,$ak1)){
					continue;
				}
				$str .= '<br /><br /><br /><br />===============<b>'.$sarr[$k].'站</b>==========<br /><br />';
				foreach ($v1 as $k2 => $v2) {
					if(!in_array($k2,$ak2)){
						continue;
					}
					$str .= '<br /><br />&nbsp;&nbsp;---------><b>'.$v2['name'].'</b><--------------------<br /><br />';
					foreach ($v2 as $k3 => $v3){
						if(strlen($v3['top'])>2){
							if(!in_array($k3,$ak3)){
								continue;
							}
							$str .= '<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;---->'.$v3['top'].'<br /><br />';
							if(is_array($v3['foot'])){
								foreach ($v3['foot'] as $v4){
									if(!in_array($v4['aid'],$ak)){
										continue;
									}
									$select = '';
									foreach ($uarray as $k5 => $v5 ){
										if($v5['aid']==$v4['aid'] && $v5['sid']==$k &&  $v5['tid']==$k2 &&  $v5['cid']==$k3 &&  $v5['lid']==$lid){
											$select = 'checked';
										}
									}
									$str .= '<input type="checkbox" value="'.$v4['aid'].'" name="cates['.$k.']['.$k2.']['.$k3.']['.$v4['aid'].']" ' . $select . '>'.$v4['name'].'&nbsp;&nbsp;';
								}
							}
						}
						
					}
				}
			}

			
		}
		
		return $str;
	}
	//用户提交批发线路处理
	function upline_site_cate($uid,$lid,$cates){
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapline` WHERE `lid`='$lid'" );
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "maplinesite` WHERE `lid`='$lid'" );
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapline`(`sid` ,`cid` ,`aid` ,`lid`, `uid`, `tid`) VALUES ";
		foreach ( $cates as $k1 => $v1 ) {
			if (empty ( $v1 ))continue;
		    $this->db->query ( "INSERT INTO `" . DB_TABLEPRE . "maplinesite`(`lid` ,`sid`,`uid`) VALUES ('$lid','$k1','$uid')" );
			foreach ( $v1 as $k2 => $v2 ) {
				if (empty ( $v2 ))continue;
				foreach ( $v2 as $k3 => $v3 ) {
					if (empty ( $v3 ))continue;
					foreach ( $v3 as $k4 => $v4 ) {
						if (empty ( $v4 ))continue;
						$sql .= "('$k1','$k3','$k4','$lid','$uid','$k2'),";
					}
				}
			}
			
		}
		$sql = substr ( $sql, 0, - 1 );
		//var_dump($sql);exit();
		return $this->db->query ( $sql );
	}
	function get_user_area_show($uid, $lid = '') {
		$larray = array ();
		if (is_numeric ( $lid )) {
			
			$lq = $this->db->query ( "SELECT `vid` FROM `" . DB_TABLEPRE . "maplineview` where `lid`='$lid'" );
			while ( $c = $this->db->fetch_array ( $lq ) ) {
				$larray [] = $c ['vid'];
			}
		
		//var_dump($larray);exit();
		}
		
		$str = '';
		$mdb = $this->db->query ( "SELECT id,sid,name,sname FROM `" . DB_TABLEPRE . "views` WHERE sid in (select aid from `" . DB_TABLEPRE . "mapuserarea` where uid='$uid')" );
		while ( $m = $this->db->fetch_array ( $mdb ) ) {
			if (empty ( $m ['sname'] )) {
				$name = $m ['name'];
			} else {
				$name = $m ['sname'];
			}
			if (in_array ( $m ['id'], $larray )) {
				$ck = ' checked';
			} else {
				$ck = '';
			}
			$str .= '<input type="checkbox" name="views[' . $m ['id'] . ']" value="' . $m ['id'] . '"' . $ck . '>' . $name . '&nbsp;&nbsp;';
		}
		return $str;
	}
	
	function deluserarea($uid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapuserarea` WHERE `uid`='$uid'" );
	}
	//景点分类管理========================================================================================
	function inlinecate($lid, $cids) {
		//var_dump($cids);exit();
		$sql = "INSERT INTO `" . DB_TABLEPRE . "maplinecate`(`lid` ,`cid`) VALUES ";
		foreach ( ( array ) $cids as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$lid','$v'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function dellinecate($lid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "maplinecate` WHERE `lid`='$lid'" );
	}
	function inlineview($lid, $cids) {
		//var_dump($cids);exit();
		$sql = "INSERT INTO `" . DB_TABLEPRE . "maplineview`(`lid` ,`vid`) VALUES ";
		foreach ( $cids as $v ) {
			if (empty ( $v ))
				continue;
			$sql .= "('$lid','$v'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function dellineview($lid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "maplineview` WHERE `lid`='$lid'" );
	}
	function upline_site($uid,$lid,$siteid) {
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "maplinesite` WHERE `lid`='$lid'" );
		$sql = "INSERT INTO `" . DB_TABLEPRE . "maplinesite`(`lid` ,`sid`,`uid`) VALUES ('$lid','$siteid','$uid')";
		return $this->db->query ( $sql );
	}
	function upline_area($uid,$lid,$siteid,$fenleiid,$leibieid,$pifaarea) {
		$this->db->query ( "DELETE FROM my_mapline WHERE `lid`='$lid'" );
		foreach ($pifaarea as $s ) {
			
		}
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapline`(`sid` ,`cid` ,`aid` ,`lid`, `uid`, `tid`) VALUES ";
		foreach ( $pifaarea as $v ) {
			$sql .= "('$siteid','$fenleiid','$v','$lid','$uid','$leibieid'),";
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
	function get_line_area($lid){
		$sitearray = $arr = array ();
		//获取用户能发布的分站
		$q1 = $this->db->query ( "SELECT * FROM `" . DB_TABLEPRE . "mapline` where `lid`='$lid'" );
		while ( $t1 = $this->db->fetch_array ( $q1 ) ) {
			$sitearray[] = $t1;
		}
		$arr['sitename'] = $this->db->result_first ( "SELECT name FROM my_site where id='$sitearray[0][sid]' limit 0,1" );
		$arr['sysname'] = $this->db->result_first ( "SELECT name FROM my_cateconfig where id='$sitearray[0][tid]' limit 0,1" );
		$arr['catename'] = $this->db->result_first ( "SELECT name FROM my_catesys where id='$sitearray[0][cid]' limit 0,1" );
		foreach ($sitearray as $k => $v){
			$arr['area'][$v['aid']] = $this->db->result_first ( "SELECT name FROM my_area where id='$v[aid]' limit 0,1" );
		}
		return $arr;
	}
	//更新景点索引分类
	function uplineindex($uid, $lid) {
		
		$sitearray = $catearray = $viewarray = array ();
		//获取用户能发布的分站
		$q1 = $this->db->query ( "SELECT `sid` FROM `" . DB_TABLEPRE . "mapusersite` where `uid`='$uid'" );
		while ( $t1 = $this->db->fetch_array ( $q1 ) ) {
			$sitearray [] = $t1 ['sid'];
		}
		//获取该线路所归属的分类
		$q2 = $this->db->query ( "SELECT `cid` FROM `" . DB_TABLEPRE . "maplinecate` where `lid`='$lid'" );
		while ( $t2 = $this->db->fetch_array ( $q2 ) ) {
			$catearray [] = $t2 ['cid'];
		}
		//获取该线路景点
		$q3 = $this->db->query ( "SELECT v.`sid` FROM `" . DB_TABLEPRE . "maplineview` as m left join `" . DB_TABLEPRE . "views` as v on m.vid=v.id where m.`lid`='$lid'" );
		while ( $t3 = $this->db->fetch_array ( $q3 ) ) {
			$viewarray [] = $t3 ['sid'];
		}
		
		$this->db->query ( "DELETE FROM `" . DB_TABLEPRE . "mapline` WHERE `lid`='$lid'" );
		$this->db->del_moreid ( 'id', DB_TABLEPRE . "mapline" );
		$sql = "INSERT INTO `" . DB_TABLEPRE . "mapline`(`sid` ,`cid` ,`aid` ,`lid`, `uid`) VALUES ";
		foreach ( $sitearray as $v1 ) {
			foreach ( $catearray as $v2 ) {
				foreach ( $viewarray as $v3 ) {
					$sql .= "('$v1','$v2','$v3','$lid','$uid'),";
				}
			}
		}
		$sql = substr ( $sql, 0, - 1 );
		return $this->db->query ( $sql );
	}
}